package cricket_behaviour

import (
	"longmen/server/config/global"
	"longmen/server/internal/services/nami/services/sports/cricket"
	"longmen/server/pkg/db/mysql/models/models_sports"
)

type (
	MatchParamApiResponse struct {
		Code  int `json:"code"`
		Query struct {
			Total int    `json:"total"`
			Type  string `json:"type"`
		} `json:"query"`
		Results []MatchParam `json:"results"`
	}

	MatchParam struct {
		ID                 int   `json:"id"`
		UniqueTournamentID int   `json:"unique_tournament_id"`
		SeasonID           int   `json:"season_id"`
		TournamentID       int   `json:"tournament_id"`
		VenueID            int   `json:"venue_id"`
		HomeTeamID         int   `json:"home_team_id"`
		AwayTeamID         int   `json:"away_team_id"`
		MatchTime          int64 `json:"match_time"`
		StatusID           int   `json:"status_id"`
		Neutral            int   `json:"neutral"`
		Coverage           struct {
			Mlive  int `json:"mlive"`
			Lineup int `json:"lineup"`
		} `json:"coverage"`
		Scores    Scores                            `json:"scores"`
		Weather   models_sports.CricketMatchWeather `json:"weather"`
		UpdatedAt int                               `json:"updated_at"`
	}
)

func (r MatchParamApiResponse) Interface() []cricket.InsertMatchInterface {
	a := make([]cricket.InsertMatchInterface, 0)
	for _, record := range r.Results {
		a = append(a, record)
	}
	global.Log.Info("count : ", len(r.Results))
	return a
}

func (c MatchParam) Get() models_sports.CricketMatch {
	return models_sports.CricketMatch{
		ID:                 c.ID,
		UniqueTournamentID: c.UniqueTournamentID,
		SeasonID:           c.SeasonID,
		TournamentID:       c.TournamentID,
		VenueID:            c.VenueID,
		HomeTeamID:         c.HomeTeamID,
		AwayTeamID:         c.AwayTeamID,
		MatchTime:          c.MatchTime,
		StatusID:           models_sports.CricketMatchStatus(c.StatusID),
		Neutral:            c.Neutral,
		Mlive:              c.Coverage.Mlive,
		Lineup:             c.Coverage.Lineup,
		Scores:             c.Scores.String(),
		Weather:            c.Weather.String(),
		UpdatedAt:          c.UpdatedAt,
	}
}
